package com.wyh.demo3;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
    public LoginServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
		String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        System.err.println(userName+";"+password);
        String myUser = "admin";
        String myPwd = "5432100";
        if(userName.equals(myUser)&&password.equals(myPwd)) {
            response.sendRedirect(request.getContextPath()+"/hello.jsp?userName="+userName);
        }else {
            request.setAttribute("message", "ܴ账号密码错误，请重新登录<br>");
            request.getRequestDispatcher("/login.jsp").forward(request, response);
        }
	}
}
